﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace CommonUtils
{
    public class FilterOfPage : IPageFilter
    {
        public void OnPageHandlerSelected(PageHandlerSelectedContext context)
        {
            (ReflectionUtil.GetSenderClassName() + "." + ReflectionUtil.GetSenderMethodName()
                + " select FilterOfPage: "
                     + context.HttpContext.Request.Path).Print();
        }

        public void OnPageHandlerExecuting(PageHandlerExecutingContext context)
        {
            (ReflectionUtil.GetSenderClassName() + "." + ReflectionUtil.GetSenderMethodName()
                + " start FilterOfPage: "
                      + context.HttpContext.Request.Path).Print();
        }

        public void OnPageHandlerExecuted(PageHandlerExecutedContext context)
        {
            (ReflectionUtil.GetSenderClassName() + "." + ReflectionUtil.GetSenderMethodName()
                + " end FilterOfPage: "
            + context.HttpContext.Request.Path).Print();
        }

        public static void AddTo(IServiceCollection services)
        {
            services.AddMvc(options => options.Filters.Add<FilterOfPage>());
        }
    }
}
